/**
 * Copyright (c) 2019, ShangHai YTO Co., Ltd.
 * All right reserved.
 * <p>
 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF YTO
 * CO., LTD.  THE CONTENTS OF THIS FILE MAY NOT BE DISCLOSED
 * TO THIRD PARTIES, COPIED OR DUPLICATED IN ANY FORM, IN WHOLE OR IN PART,
 * WITHOUT THE PRIOR WRITTEN PERMISSION OF YTO
 * CO., LTD.
 */
package org.sc.xl.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.sc.xl.dao.DimMapper;
import org.sc.xl.entity.UserOrgMdmPO;
import org.sc.xl.service.DimService;
import org.sc.xl.vo.UserOrgMdmVO;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author FXL
 * @description: TODO 请在此添加描述
 * @reason: TODO ADD REASON(可选)
 * @date 2021/11/17 21:30
 * @since JDK 1.8
 */
@Service
public class DimServiceImpl extends ServiceImpl<DimMapper, UserOrgMdmPO> implements DimService {


    @Override
    public List<UserOrgMdmVO> selectList(Map<String, Object> param) {
        List<String> orgTypeList = (List<String>) param.get("org_type");
        QueryWrapper<UserOrgMdmPO> wrapper = new QueryWrapper<>();
        wrapper.in((Boolean) param.get("orgTypeInCondition"), "org_type", orgTypeList)
                .eq("region_active_flag", "0")
                .eq((Boolean) param.get("regionCondition"), "org_code", param.get("regionCode"))
                .eq((Boolean) param.get("centerCondition"), "org_code", param.get("transferCode"))
                .eq((Boolean) param.get("branchCondition"), "org_code", param.get("branchCode"))
                .eq((Boolean) param.get("subCondition"), "org_code", param.get("subCode"));
        List<UserOrgMdmPO> userOrgMdmPOS = baseMapper.selectList(wrapper);
        List<UserOrgMdmVO> userOrgMdmVOS = JSONArray.parseArray(JSON.toJSONString(userOrgMdmPOS), UserOrgMdmVO.class);
        return userOrgMdmVOS;
    }


    @Override
    public List<UserOrgMdmVO> selectByOrgCode(String orgCode) {
        QueryWrapper<UserOrgMdmPO> wrapper = new QueryWrapper<>();
        wrapper.eq("org_code", orgCode);
        List<UserOrgMdmPO> userOrgMdmPOS = baseMapper.selectList(wrapper);
        return JSONArray.parseArray(JSON.toJSONString(userOrgMdmPOS), UserOrgMdmVO.class);
    }
}
